<template>
  <!-- 设置人员 -->
  <div class="person-list-wrap">
    <!-- 查询条件 -->
    <el-row type="flex" justify="space-between">
      <el-form :inline="true" :model="searchForm" class="personList-form-inline" @submit.native.prevent  style="width: 100%;">
        <el-form-item  style="width: 100%;">
          <el-input
            @change="search"
            placeholder="请输入姓名/帐号/手机号"
            v-model="searchForm.name"
            @keyup.enter.native="search"
            clearable>
          </el-input>
        </el-form-item>
      </el-form>
    </el-row>
    <!-- 数据列表 -->
    <el-table
      v-loading="loading"
      ref="multipleTable"
      tooltip-effect="dark"
      :data="tableData"
      @selection-change="handleSelectionChange"
      style="width: 100%">
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column label="账户" prop="accountName"></el-table-column>
      <el-table-column label="姓名" prop="name"></el-table-column>
      <el-table-column label="角色" prop="roleNames"></el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="currentPage"
      :page-sizes="[10, 50, 100]"
      :page-size="10"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
    <div class="more-btns">
      <el-button type="primary" @click="submitPserson">提交</el-button>
    </div>
  </div>
</template>
<style>
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 150px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 100%;
  }
  .personList-form-inline .el-form-item__content {
    width: 100%;
  }
</style>
<script>
  import { getVideoUsers} from '@/api/sysConfig'
  export default {
    name: 'PersonList',
    // 引入子组件
    components: {

    },
    props: {
      updateSetPerson: {
        type: Function,
        required: true
      },
      oldUserList: {
        type: Array
      },
      orgId:{
        type: Number
      }
    },
    data() {
      return {
        loading: false,
        dialogEditInfo: false,
        multipleSelection: [],
        // 搜索条件
        searchForm: {
          name: ''
        },
        // 列表数据
        tableData: [],
        // 分页
        currentPage: 1,
        pageSize: 10,
        total: 0,
      }
    },
    created() {//入口
      let that = this
      // 加载列表
      that.getTableData()
    },
    methods: {
      // 获取列表数据
      getTableData(pageIndex, pageSize) {
        let that = this
        that.loading = true
        let parames = {
          orgId: that.orgId,
          queryType: 1,
          name: that.searchForm.name.trim(),
          pageSize: that.pageSize,
          pageIndex: that.currentPage - 1
        }
        // 获取列表信息
        getVideoUsers(parames).then(res => {
          that.tableData = res.data
          that.total = res.total
          that.loading = false
          that.toggleSelection(that.tableData)
        })
      },
      search() {
        this.getTableData(1)
      },
      handleSizeChange(pageSize) {
        this.getTableData(1, pageSize)
      },
      handleCurrentChange(currentPage) {
        this.getTableData(currentPage)
      },
      // 关闭编辑弹框
      submitPserson() {
        let that = this
        that.updateSetPerson(that.multipleSelection)
      },
      handleSelectionChange(val) {
        this.multipleSelection = val
      },
      //默认选中
      toggleSelection(rows) {
        this.$nextTick(function () {
          if (rows) {
            rows.forEach(row => {
              for(var i=0;i<this.oldUserList.length;i++){
                if(row.accountName==this.oldUserList[i].username){
                    this.$refs.multipleTable.toggleRowSelection(row, true);
                }
              }
            });
          } else {
            this.$refs.multipleTable.clearSelection();
          }
        })
      },
    }

  }
</script>
